#pragma once

#include <D3DX11.h>
#include <DxErr.h>
#include <vector>
#include <map>
#include <fstream>

#include "../Common.h"

#include "Obj.h"

namespace DirectX
{
  class Obj
  {
  public:
    Obj(void);
    virtual ~Obj(void);


    HRESULT Create(const std::string strFilename );
    void    Destroy();

    unsigned int GetNumVertices();

    unsigned int GetNumIndices();

    WORD* GetIndices();

    Vertex* GetVertices();

    unsigned GetNumMaterials();

    Material* GetMaterials();

    static void InitMaterial( Material* pMaterial );
  private:

    HRESULT LoadGeometryFromOBJ( const std::string strFilename );
    HRESULT LoadMaterialsFromMTL( const std::string strFileName );



    DWORD   AddVertex( UINT hash, Vertex* pVertex );
    //void    DeleteCache();

    //ID3D11Device* m_pd3dDevice;    // Direct3D Device object associated with this mesh
    //ID3DXMesh* m_pMesh;         // Encapsulated D3DX Mesh

    std::vector<Vertex> m_Vertices;
    std::vector<unsigned int> m_Indices;
    std::vector<unsigned int> m_Attributes;

    std::map<unsigned int, Vertex*> m_map;

    //CGrowableArray <CacheEntry*> m_VertexCache;   // Hashtable cache for locating duplicate vertices  
    std::map<std::string, Material*> m_Materials;     // Holds material properties per subset

    std::string m_strMediaDir;

    //WCHAR   m_strMediaDir[ MAX_PATH ];               // Directory where the mesh was found
  };

}